<template>
    <div class="DashBoard">
        <div class="row row1">
            <row1 :organOverview="workSpaceData.organOverview"
                  :todayData="workSpaceData.todayData"
                  :updateTime="workSpaceData.updateTime"></row1>
        </div>
        <div class="row row2">
            <row2 :backlog="workSpaceData.backlog"
                  :todayData="workSpaceData.todayData"
                  :updateTime="workSpaceData.updateTime"></row2>
        </div>
        <div class="row row3">
            <row3 :backlog="workSpaceData.backlog"></row3>
        </div>
        <div class="row row4">
            <row4 :transportTaskList="workSpaceData.transportTaskList"></row4>
        </div>
        <div class="row row5">
            <row5 :orderLineChart="workSpaceData.orderLineChart"
                  :updateTime="workSpaceData.updateTime"></row5>
        </div>
    </div>
</template>

<script>
import { delToken } from '@/utils/storage'
import { getMenus, getWorkSpace } from '@/api/dashboard'
import { mapState } from 'vuex'
import { Message } from 'element-ui'
import dayjs from 'dayjs'
import store from '@/store'

export default {
    name: 'DashBoard',
    created () {
        this.getMenus()
        this.getWorkSpace()
    },
    mounted () {
        this.$store.commit('setPageLoading', false)
    },
    data () {
        return {
            workSpaceData: {}
        }
    },
    methods: {
        logout () {
            delToken()
            this.$router.push('/Login')
        },
        async getMenus () {
            const res = await getMenus()
            // console.log(res)
        },
        async getWorkSpace () {
            const res = await getWorkSpace()
            if (res.status === 200 && Object.keys(this.workSpaceData).length) Message.success('数据已更新！')
            this.workSpaceData = res.data.data
            // console.log(this.workSpaceData)
            this.workSpaceData.updateTime = dayjs().format('YYYY-MM-DD HH:mm:ss')
        }
    },
    computed: {
        ...mapState(['dataRefresh'])
    },
    watch: {
        dataRefresh (val) {
            if (val) this.getWorkSpace()
            this.$store.commit('setDataRefresh', false)
        }
    }
}
</script>

<style scoped lang="scss">
</style>
